package com.ruoyi.back.v1

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.mapper.DigitalPeopleInfoManagerMapper
import io.swagger.annotations.Api
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import io.swagger.annotations.ApiOperation
import org.apache.ibatis.annotations.Mapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.*
import javax.persistence.*


@Entity
@TableName("fly_digital_people_info_manager")
@Table(name = "fly_digital_people_info_manager")
@ApiModel("数字人信息管理")
data class DigitalPeopleInfoManager(

    @TableId(type = IdType.AUTO)
    @ApiModelProperty("id 更新的时候需要传递")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    @ApiModelProperty("定制数字人介绍视频")
    var customizeDigitalPeopleIntroVideo: String? = null,

    @ApiModelProperty("数字人换脸介绍图片")
    var digitalPeopleChangeFaceIntroPic: String? = null,

    @ApiModelProperty("定制数字人价格")
    var createDigitalPeoplePrice: Double? = 0.0,

    @ApiModelProperty("数字人换脸价格")
    var digitalPeopleChangeFacePrice: Double? = 0.0,

    @ApiModelProperty("体验最大时长")
    var experienceMaxTime: Int? = 0,

    @ApiModelProperty("新手引导视频")
    var beginnerBootstrappingVideo: String? = null,

    @ApiModelProperty("推广和会员分享页设置")
    var spreadMemberShareUrl: String? = null,

    @ApiModelProperty("常见问题 富文本格式")
    var commonQuestion: String? = null,

    @ApiModelProperty("提现须知 富文本格式")
    var withdrawInstruction: String? = null,
)





@Service
@Transactional(rollbackFor = [Exception::class])
class DigitalPeopleInfoManagerService : ServiceImpl<DigitalPeopleInfoManagerMapper, DigitalPeopleInfoManager>() {

    fun digitalPeopleInfo(): Data<DigitalPeopleInfoManager> =
        Ok("获取成功", getOne(KtQueryWrapper(DigitalPeopleInfoManager::class.java).last("limit 1")))


    fun info(): DigitalPeopleInfoManager = getOne(KtQueryWrapper(DigitalPeopleInfoManager::class.java).last("limit 1"))

    fun saveDigitalPeopleInfo(digitalPeopleInfoManager: DigitalPeopleInfoManager): Data<Boolean> =
        Ok("更新成功", saveOrUpdate(digitalPeopleInfoManager))
}


@RestController
@RequestMapping("/system/digitalPeopleInfo")
@Api(tags = ["数字人介绍相关接口"])
class DigitalPeopleInfoController {

    @Autowired
    private lateinit var digitalPeopleInfoManagerService: DigitalPeopleInfoManagerService

    @ApiOperation("保存或者修改数字人介绍")
    @PostMapping("saveDigitalPeopleInfo")
    fun saveDigitalPeopleInfo(@RequestBody digitalPeopleInfoManager: DigitalPeopleInfoManager): Data<Boolean> =
        digitalPeopleInfoManagerService.saveDigitalPeopleInfo(digitalPeopleInfoManager)

    @ApiOperation("获取数字人介绍信息")
    @GetMapping("removeDigitalPeopleInfo")
    fun digitalPeopleInfo(): Data<DigitalPeopleInfoManager> =
        digitalPeopleInfoManagerService.digitalPeopleInfo()
}





